// RestaurantPage.cs
// Facebook/Framework/Service
// Copyright (c) 2007, Nikhil Kothari. All Rights Reserved.
//

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using Facebook.Service.Core;

namespace Facebook.Service {

    /// <summary>
    /// The restaurant information associated with a PresencePage.
    /// </summary>
    public sealed class RestaurantPage : BusinessPage {

        private bool _paymentOptionsTransformed;
        private bool _servicesTransformed;
        private bool _specialitiesTransformed;

        internal RestaurantPage(Hashtable pageState)
            : base(pageState) {
        }

        /// <summary>
        /// Recommended attire at the restaurant.
        /// </summary>
        public string Attire {
            get {
                return GetState<string>("attire") ?? String.Empty;
            }
        }

        /// <summary>
        /// The culinary team at the restaurant.
        /// </summary>
        public string CulinaryTeam {
            get {
                return GetState<string>("culinary_team") ?? String.Empty;
            }
        }

        /// <summary>
        /// The set of supported payment options at the restaurant.
        /// </summary>
        public string PaymentOptions {
            get {
                if (_paymentOptionsTransformed == false) {
                    return TransformPaymentOptions();
                }
                return GetState<string>("payment_options");
            }
        }

        /// <summary>
        /// The price range at the restaurant.
        /// </summary>
        public string PriceRange {
            get {
                return GetState<string>("price_range") ?? String.Empty;
            }
        }

        /// <summary>
        /// The set of services offered by the restaurant.
        /// </summary>
        public string Services {
            get {
                if (_servicesTransformed == false) {
                    return TransformServices();
                }
                return GetState<string>("restaurant_services");
            }
        }

        /// <summary>
        /// The set of specialities offered by the restaurant.
        /// </summary>
        public string Specialities {
            get {
                if (_specialitiesTransformed == false) {
                    return TransformSpecialities();
                }
                return GetState<string>("restaurant_specialities");
            }
        }

        private string TransformPaymentOptions() {
            Debug.Assert(_paymentOptionsTransformed == false);

            object o = this["payment_options"];
            string options = FacebookResponse.CoerceOptions(o);

            this["payment_options"] = options;
            _paymentOptionsTransformed = true;

            return options;
        }

        private string TransformServices() {
            Debug.Assert(_servicesTransformed == false);

            object o = this["restaurant_services"];
            string services = FacebookResponse.CoerceOptions(o);

            this["restaurant_services"] = services;
            _servicesTransformed = true;

            return services;
        }

        private string TransformSpecialities() {
            Debug.Assert(_specialitiesTransformed == false);

            object o = this["restaurant_specialities"];
            string specialities = FacebookResponse.CoerceOptions(o);

            this["restaurant_specialities"] = specialities;
            _specialitiesTransformed = true;

            return specialities;
        }
    }
}
